<h1>Edit : <?=$person->fullname()?><div class="close">x</div></h1>

<form action="<?php echo url('person/edit/' . $person->id); ?>" method="post" class="ajax">

    <input type="hidden" name="person[id]" value="<?=$person->id?>" />
    <input type="hidden" name="person[user]" value="<?=$person->user?>" />
    <input type="hidden" name="person[parents]" value="<?=$person->parents?>" />

    <div class="part">

        <div class="line">
            <label for="firstnames">Firstnames</label>
            <input type="text" name="person[firstnames]" id="firstnames" value="<?=$person->firstnames?>" />
        </div>

        <div class="line">
            <label for="lastname">Lastname</label>
            <input type="text" name="person[lastname]" id="lastname" value="<?=$person->lastname?>" />
        </div>

        <div class="line">
            <label for="maidenname">Maiden name</label>
            <input type="text" name="person[maidenname]" id="maidenname" value="<?=$person->maidenname?>" />
        </div>

        <div class="line">
            <label for="nickname">Nickname</label>
            <input type="text" name="person[nickname]" id="nickname" value="<?=$person->nickname?>" />
        </div>

        <div class="line">
            <label for="gender">Gender</label>
            <input type="radio" name="person[gender]" value="1" <?php if($person->gender == 1) echo 'checked'; ?> /> M
            <input type="radio" name="person[gender]" value="2" <?php if($person->gender == 2) echo 'checked'; ?> /> F
        </div>

    </div>

    <div class="part">

        <?php $index = 0; ?>
        <?php foreach($person->events() as $index => $event): ?>
        <div class="line event" rel="<?=$event->id?>">
            <input type="hidden" name="event[<?=$index?>][id]" value="<?=$event->id?>" />
            <div>
                <input type="text" name="event[<?=$index?>][name]" placeholder="Event" class="medium require" value="<?=$event->name?>">
                <input type="text" name="event[<?=$index?>][date]" placeholder="Date" class="medium" value="<?=$event->date?>">
                <input type="text" name="event[<?=$index?>][place]" placeholder="Place" value="<?=$event->place?>">
            </div>
            <textarea name="event[<?=$index?>][description]"><?=$event->description?></textarea>
        </div>
        <?php endforeach; ?>

        <div id="content-events"></div>

        <a href="#" class="add-event">+ event</a>

    </div>

    <div class="clearfix"></div>

    <div class="actions">
        <input type="submit" value="Save" />
        <div class="clearfix"></div>
    </div>

</form>

<div class="hide event-form-model">

    <div class="line event" rel="{index}">
        <div>
            <input type="text" name="event[{index}][name]" placeholder="Event" class="medium require">
            <input type="text" name="event[{index}][date]" placeholder="Date" class="medium">
            <input type="text" name="event[{index}][place]" placeholder="Place">
        </div>
        <textarea name="event[{index}][description]" placeholder="Description"></textarea>
    </div>

</div>